package cn.tedu.egweibo1.controller;

import ch.qos.logback.core.joran.util.beans.BeanUtil;
import cn.tedu.egweibo1.base.reponse.JsonResult;
import cn.tedu.egweibo1.mapper.UserMapper;
import cn.tedu.egweibo1.pojo.dto.UserInsertParam;
import cn.tedu.egweibo1.pojo.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
@Slf4j
@RestController
@RequestMapping("/v1/user/")
public class UserController {
    @Autowired
    private UserMapper userMapper;
    @PostMapping("add")
    //public String insert(@RequestBody UserInsertParam userInsertParam){
    public JsonResult insert(@RequestBody UserInsertParam userInsertParam){
        //System.out.println("userInsertParam"+userInsertParam);
        log.info("userInsertParam"+userInsertParam);
        User user = new User();
        BeanUtils.copyProperties(userInsertParam,user);
        user.setCreateTime(new Date());
        userMapper.insert(user);
        log.info("user"+user);
        return JsonResult.ok();
    }
}
